package br.com.damazzy.util {
	
	import mx.formatters.DateFormatter;
	
	public class FormataData {
		private static var formataDt:DateFormatter = new DateFormatter();
		
		public static function formataData(data:Date, mascara:String=""):String {
			var dateString: String = null;
			if(data != null) {
				if(data.getFullYear() > 1) {
					if(mascara == "" || mascara == null)
						formataDt.formatString = "DD/MM/YYYY";
					else
						formataDt.formatString = mascara.toUpperCase();
					
					dateString = formataDt.format(data);
					return dateString;
				}else{
					return "";
				}
			}else{
				return "";
			}
		}
		public static function formataDataHora(data:Date, mascara:String=""):String {
			if(data != null) {
				if(data.getFullYear() > 1) {
					if(mascara == "" || mascara == null)
						formataDt.formatString = "DD/MM/YYYY JJ:NN:SS";
					else
						formataDt.formatString = mascara.toUpperCase();
					
					return formataDt.format(data);
				}else{
					return "";
				}
			}else{
				return "";
			}
		}
		
		public static function formataDataHoraSemSegundo(data:Date, mascara:String=""):String {
			if(data != null) {
				if(data.getFullYear() > 1) {
					if(mascara == "" || mascara == null)
						formataDt.formatString = "DD/MM/YYYY JJ:NN";
					else
						formataDt.formatString = mascara.toUpperCase();
					
					return formataDt.format(data);
				}else{
					return "";
				}
			}else{
				return "";
			}
		}
		
		public static function formataHora(data:Date, mascara:String=""):String {
			if(data != null) {
				if(data.getFullYear() > 1) {
					if(mascara == "" || mascara == null)
						formataDt.formatString = "JJ:NN:SS";
					else
						formataDt.formatString = mascara.toUpperCase();
					
					return formataDt.format(data);
				}else{
					return "";
				}
			}else{
				return "";
			}
		}
		
		public static function formata(data:Date, mascara:String):String {
			if(mascara == null || mascara == "")
				mascara = "DD/MM/YYYY";
			
			if(data != null) {
				if(data.getFullYear() > 1) {
					formataDt.formatString = mascara.toUpperCase();
					
					return formataDt.format(data);
				}else{
					return "";
				}
			}else{
				return "";
			}
		}
		
		public static function formataExtenso(data:Date, mostraDiaSemana:Boolean = false):String {
			if(data != null) {
				if(data.getFullYear() > 1) {
					var arr:Array = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"];
					var arrSemana:Array = ["Domingo", "Segunda-Feira", "Terça-Feira", "Quarta-Feira", "Quinta-Feira", "Sexta-Feira", "Sábado"];
					
					return ((mostraDiaSemana)?(String(arrSemana[data.day]) + " - "):"") + String(data.getDate()) + " de " + arr[data.getMonth()] + " de " + String(data.getFullYear());
				}else{
					return "";
				}
			}else{
				return "";
			}
		}		
	}
}